package com.bbs.services;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bbs.bean.BbsUserInfo;
import com.bbs.dao.BbsUserInfoDao;

@Transactional
@Service
public class BbsUserInfoManager {
	private BbsUserInfoDao bbsUserInfoDao;

	public BbsUserInfoDao getBbsUserInfoDao() {
		return bbsUserInfoDao;
	}

	public void setBbsUserInfoDao(BbsUserInfoDao bbsUserInfoDao) {
		this.bbsUserInfoDao = bbsUserInfoDao;
	}
	
	public void save(BbsUserInfo bbsUserInfo){
		bbsUserInfo.setUserIntergral(0);
		bbsUserInfo.setUserLevel(1);
		bbsUserInfo.setUserState(1);
		bbsUserInfo.setUserRegisterTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
		bbsUserInfoDao.save(bbsUserInfo);
	}
	
	public void update(BbsUserInfo bbsUserInfo){
		bbsUserInfoDao.update(bbsUserInfo);
	}
	
	public void delete(int id){
		bbsUserInfoDao.deleteById(id);
	}
	
	public List<BbsUserInfo> findAll(){
		return bbsUserInfoDao.findAll();
	}
	
	public BbsUserInfo findId(int id){
		return bbsUserInfoDao.getById(id);
	}

	public void delete(String ids) {
		String[] strIds=ids.split(",");
		for(String id:strIds){
			Integer id1=Integer.parseInt(id);
			bbsUserInfoDao.deleteById(id1);
		}
	}
	
	public List<BbsUserInfo> findByPage(int page){
		return bbsUserInfoDao.findAllByPage(page);
	}
	
	public int getCountInfo(){
		return bbsUserInfoDao.getCountInfo();
	}

	public int findCount() {
		return bbsUserInfoDao.getCountInfo();
	}

	public BbsUserInfo getUniqued(BbsUserInfo bbsUserInfo,String str) {
		BbsUserInfo bbsUserInfo1=new BbsUserInfo();
		bbsUserInfo1=bbsUserInfoDao.getUniqued(bbsUserInfo, str);	
		return bbsUserInfo1;
		
	}
}
